package com.minminaya.source;

import java.util.Stack;

public class Algorithm_3 {

    public static class ListNode {
        int value;
        ListNode next;
    }


    public static void printListInverselyUsingIteration(ListNode root) {
        Stack<ListNode> stack = new Stack<>();
        while (root != null) {
            stack.push(root);
            root = root.next;
        }

        ListNode tempListNode;
        while (!stack.isEmpty()) {
            tempListNode = stack.pop();
            System.out.print(tempListNode.value + "");
        }
    }

    /**
     * 递归特有的性质，反向打印
     */
    public static void printListInverselyUsingRecursion(ListNode root) {
        if (root != null) {
            printListInverselyUsingRecursion(root.next);
            System.out.print(root.value + "");
        }
    }

}
